package com.china08.yxyapi.api.manage.edu.platform.continuedu.lesson;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.continuedu.YxyContinueduLesson;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.repository.db.continuedu.YxyContinueduLessonRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class YxyContinueduLessonUpdController extends YxyApiBaseController {

    @Autowired
    YxyContinueduLessonRepository conLessonRepository;

    @ApiOperation(value = "")
    @RequestMapping(value = "/api_yw/manage/edu/platform/continuedu/lesson/upd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String id = reqModel.id;
        String name = reqModel.name;
        String summary = reqModel.summary;
        String cover = reqModel.cover;

        YxyContinueduLesson lesson = conLessonRepository.findById(id);
        if (lesson != null) {
            lesson.setName(name);
            lesson.setSummary(summary);
            lesson.setCover(cover);
            lesson.setLastUpDate(new Date());
            conLessonRepository.save(lesson);
        }
    }

    public static class ReqModel extends YxyApiReqModel {
        public String id;
        public String name;
        public String summary;
        public String cover;

        @Override
        public void autoCheck() {

        }
    }
}
